<template>
	<view class="content">
		<image class="login-image" src="../../static/logititle.png" mode="widthFix" />
		<view class="loginBox">
			<view class="top-box">
				<view class="input-title">
					<text class="text1">{{$t('login.title')}}</text>
					<text class="text2">{{$t('login.tip')}}</text>
				</view>
				<u--form labelPosition="left" :borderBottom="false" labelWidth="32" :model="loginInfo" :rules="rules" ref="uForm">
					<u-form-item prop="email">
						<u--input 
						class="formitem input-border" 
						v-model="loginInfo.email"
						 prefixIcon="email" 
						 :prefixIconStyle="prefixIconStyle" 
						 :customStyle="{paddingLeft:'34rpx',borderRadius:'17rpx'}"
						 border="none" 
						 :placeholder="$t('input.email')"/>
					</u-form-item>
					<u-form-item prop="password">
						<u--input 
						class="formitem input-border" 
						:password="true" 
						v-model="loginInfo.password"
						 prefixIcon="lock-open" 
						 :prefixIconStyle="prefixIconStyle" 
						 :customStyle="{paddingLeft:'34rpx',borderRadius:'17rpx'}"
						 border="none" 
						 :placeholder="$t('input.password')"/>
					</u-form-item>
				</u--form>
				<view class="forgot-text"><text @click="toNavigate">{{$t('login.forget')}}?</text></view>
			</view>
			<view class="submit">
			 <button class="loginBth" @click="toLogin">{{$t('login.sumbit')}}</button>
			 <view class="loginTips" @click="toRegister">
			 	<text style="color: #B2B2B2;">{{$t('login.register')}}?</text>
			 	<text>{{$t('login.register1')}}</text>
			 </view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				loginInfo:{
					email:"",
					password:""
				},
				prefixIconStyle:{
					fontSize:'44rpx',
				}
			}
		},
		computed:{
			rules(){
				return {
					'email': [{
						type: 'string',
						required: true,
						message: this.$t('err.email'),
						trigger: ['blur', 'change']
					},
					{
						validator: (rule, value, callback) => {
							var reg = /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
							if (!reg.test(value)) {
								callback(new Error(this.$t('err.email1')));
							} else {
								callback();
							}
						},
						trigger: 'blur'
					}],
					'password': {
						type: 'string',
						required: true,
						message: this.$t('err.password'),
						trigger: ['blur', 'change']
					}
				}
			}
		},
		methods: {
				toLogin(){
					this.$refs.uForm.validate().then(async (res)=>{
						 const {data:sue} = await this.$api('/front/login','POST',this.loginInfo)
						 if(sue.code!=200)return uni.$u.toast(sue.msg)
						 uni.setStorageSync('token',sue.data.token)
						 uni.reLaunch({
						 	url:'/pages/gaming/gaming'
						 })
					})
					
				},
				//注册
                toRegister(){
					uni.navigateTo({
						url:'/pages/register/register'
					})
				},
				//重置
				toNavigate(){
					uni.navigateTo({
						url:'/pages/forgetPassword/forgetPassword'
					})
				}
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		width: 100vw;
		min-height: 100vh;
		background: linear-gradient( 180deg, #000000 0%, #3C3C3C 100%);
		display: flex;
		flex-direction: column;
		align-items: center;
		box-sizing: border-box;
		padding-top: 18vh;
		font-size: 20rpx;
		font-family: my-font;
		.login-image{
			width: 300rpx;
			margin-bottom: 60rpx;
		}
		.loginBox{
			width: calc(100vw - 100rpx);
			background-color: #373451;
			border-radius: 68rpx;
			box-sizing: border-box;
			padding: 50rpx;
			display: flex;
			flex-direction: column;
			justify-content: space-between;
			.top-box{
				width: 100%;
				flex: 1;
				.input-title{
					display: flex;
					flex-direction: column;
					text-align: center;
					color: #B2B2B2;
					font-size: 20rpx;
					margin-bottom: 54rpx;
					.text1{
						font-size: 40rpx;
					}
				}
				.formitem{
					width: 100%;
					height: 90rpx;
			     }
				.forgot-text{
					text-align: right;
					margin-top: 15rpx;
					color: #B2B2B2;
				}
			}
			.submit{
				width: 100%;
				margin-top: 120rpx;
				.loginBth{
					width: 100%;
					height: 100rpx;
					border-radius: 26rpx;
					font-size: 33rpx;
					font-weight: bold;
					line-height: 100rpx;
					color: #fff;
					background-color: #926FBF;
				}
				.loginTips{
					text-align: center;
					margin-top: 15rpx;
					color: #fff;
					font-size: 22rpx;
				}
			}
			
		}
	}
</style>
